
//This GUI Java application will prompt user with a GUI to create a 
//calendar event, user will select time zone, start date/time as well 
//as end date/time.
//
//User has option to make event all day as well as creating a rule
//
//A rule can add a frequency [daily, weekly, monthly, yearly] 
//a count [amount of times the event will occur
//an interval [the gap between the event, ex every 3 days, 1year,
//or every other month
//
//Program checks all values for validity as well as logical errors
//
//@Author Robert Patch - Palms Group

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.TimeZone;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

import net.fortuna.ical4j.data.CalendarOutputter;
import net.fortuna.ical4j.data.ParserException;
import net.fortuna.ical4j.model.DateTime;
import net.fortuna.ical4j.model.Dur;
import net.fortuna.ical4j.model.Recur;
import net.fortuna.ical4j.model.ValidationException;
import net.fortuna.ical4j.model.WeekDay;
import net.fortuna.ical4j.model.component.VEvent;
import net.fortuna.ical4j.model.property.CalScale;
import net.fortuna.ical4j.model.property.Clazz;
import net.fortuna.ical4j.model.property.Comment;
import net.fortuna.ical4j.model.TextList;
import net.fortuna.ical4j.model.property.DtStamp;
import net.fortuna.ical4j.model.property.Location;
import net.fortuna.ical4j.model.property.ProdId;
import net.fortuna.ical4j.model.property.RRule;
import net.fortuna.ical4j.model.property.Resources;
import net.fortuna.ical4j.model.property.Version;
import net.fortuna.ical4j.util.UidGenerator;
import net.fortuna.ical4j.data.CalendarBuilder;

import javax.swing.*;

import java.lang.*;
import java.net.SocketException;

public class PalmsCalGUI implements ActionListener {
	
	//instance variables
	
	//Arraylist of an arraylist of an array of its is used to simulate a database version
	//of a calendar system used to validate days via a 1 (valid date) or 0 (not a valid date
	static ArrayList<ArrayList<int[]>> isDay = new ArrayList<ArrayList<int[]>>();
	//see DropDwonMenu class
	static DropDownMenu drpYears;
	static DropDownMenu drpMonths;
	static DropDownMenu drpDayShort;
	static DropDownMenu drpDayLeapYear;
	static DropDownMenu drpDayThirty;
	static DropDownMenu drpDayLong;
	static DropDownMenu drpTimeHr;
			
	static DropDownMenu drpYearsMid;
	static DropDownMenu drpMonthsMid;
	static DropDownMenu drpDayShortMid;
	static DropDownMenu drpDayLeapYearMid;
	static DropDownMenu drpDayThirtyMid;
	static DropDownMenu drpDayLongMid;
	static DropDownMenu drpTimeHrMid;
	static DropDownMenu drpTimeMinMid;
	
	static DropDownMenu drpTimeMin;
	static DropDownMenu drpYrUntil;
	static DropDownMenu drpMthUntil;
	static DropDownMenu drpDayUntil;
	
	static DropDownMenu drpRegion;
	static DropDownMenu drpClazz;
	
	static DropDownMenu clazz;
	//JComboBox's that will be added to JPanels and then added to a final frame
	//starting date combobox's
	static JComboBox comboYears;
	static JComboBox comboMonths;
	static JComboBox comboDaysShort;
	static JComboBox comboDaysLeap;
	static JComboBox comboDaysThirty;
	static JComboBox comboDaysLong;
	static JComboBox comboHours;
	static JComboBox comboMinutes;
	//ending date combobox's
	static JComboBox comboYearsMid;
	static JComboBox comboMonthsMid;
	static JComboBox comboDaysShortMid;
	static JComboBox comboDaysLeapMid;
	static JComboBox comboDaysThirtyMid;
	static JComboBox comboDaysLongMid;
	static JComboBox comboHoursMid;
	static JComboBox comboMinutesMid;
	//recurrence until date comboboxes
	static JComboBox untilYr;
	static JComboBox untilMth;
	static JComboBox untilDay;
	
	static JComboBox region;		   //region combobox
	
	static JComboBox clazzes;			  //class combobox
	
	
	static Recur recur = new Recur();  //new Recur object, values such as count, 
									   //interval, and frequency are associated 
									   //with this object
	
	static String[] daysLong; 		   //array holding 31 ints (could have  
									   //used boolean to save space)
	
	//JButtons that will be added to JPanels and then added to a final frame
	static JButton create;			   //create calendar
	static JButton reset;			   //reset board
	static JButton createRule;		   //checkbox that enables the recur rule options
	static JButton ruleReset;		   //resets the recur rules
	
	static JRadioButton daily;		   //sets frequency
	static JRadioButton weekly;		   //sets frequency
	static JRadioButton monthly;       //sets frequency
	static JRadioButton yearly;	       //sets frequency
	static JRadioButton noEndDate;     //if set the recurrence will last forever
	static JRadioButton endAfter;      //sets a specific amount of occurences (COUNT)
	static JRadioButton endBy;		   //sets a specific date to end occurences (UNTIL)
	
	//JCheckBoxs that will be added to JPanels and then added to a final frame
	static JCheckBox isAllDay;		   //sets end date to 23:59pm of same day
	static JCheckBox rule;
	static RRule rrule;	   		   //enables options to create a recurrence rule
	static JCheckBox changeYr; 		   //defaults are set to same yr/mth/day, this checkbox, enabled those to be changed
	static JCheckBox regionCheck; 	   //enables region to be changed
	static JCheckBox addComment;
	static JCheckBox addLocation;
	static JCheckBox addResources;
	
	//JPanels used create interface
	static JPanel regionPanel;		
	static JPanel bottomRecur;
	static JPanel endAfterPan;
	static JPanel jPan = new JPanel();
	static JPanel jPanDailyFull = new JPanel();
	static JPanel jPanDaily = new JPanel();
	static JPanel recurSec = new JPanel();
	static JPanel recurPanel2 = new JPanel();
	static JPanel recurPanel1 = new JPanel();
	static JLabel recurEvery;
	static JLabel recurAfter = new JLabel("");
	static JPanel ruleCreate = new JPanel();
	static JPanel calendarEvent = new JPanel();
	static JPanel locationPanel = new JPanel();
	static JPanel commentPanel = new JPanel();
	static JPanel resourcesPanel = new JPanel();
	
	//JLables used to create interface
	static JLabel calEvent;
	static JLabel occur;
	static JLabel yr = new JLabel("Years:");
	static JLabel mt = new JLabel("Months");
	static JLabel dy = new JLabel("Days");
	static JLabel isSet = new JLabel("");
	
	
	
	
	static JPanel grid = new JPanel(new GridLayout(1,0));
	//creating new JPanel with GridLayout, this is used to add other JPanels too
	//essentially I used this "nested layout" to create new lines within the GUI
	static JPanel boxLay = new JPanel();
	//create instance variable of a GridLayout with one column and as many rows as needed
	static GridLayout theGrid = new GridLayout(0,1);
			
	//creating top mid and bottom levels to be eventually added to the boxLay JPanel
	static JPanel topLevel = new JPanel();
	static JPanel midLevel = new JPanel();
	static JPanel botLevel = new JPanel();
	static JPanel thirdLevel = new JPanel();
	static JPanel fourthLevel = new JPanel();
	static JPanel fifthLevel = new JPanel();
	static JPanel sixthLevel = new JPanel();
	static JPanel seventhLevel = new JPanel();
	static JPanel eighthLevel = new JPanel();
	static JPanel recurPanel = new JPanel();
	
	//TTextFields used to create GUI;
	static JTextField text;				//calendar event name
	static JTextField count;		    //interval text field
	static JTextField endAfterText;		//count text field (how many times will the event repeat
	static JTextField location;			//specific location, ex building 5 room 3
	static JTextField comment;
	static JTextField resources;
	
	//these variables are the 5 values needed in the createCalendar() to successfully
	//create a .ics file
	private static int strYr = -1;		//starting year/month/day ect, set to -1 because of DateCheck method
	private static int strMth = -1;		
	private static int strDay = -1;		
	private static int strHr;			
	private static int strMin;
	private static String strTxt;
	private static String error = "";
	private static String finalClass;
	private static String strLocation;
	private static String strComment;
	
	private static TextList resourceList;
	//these 5 values are the "end times" needed when creating .ics file
	private static int strYrMid = -1;	//ending year/month/day,ect
	private static int strMthMid = -1;
	private static int strDayMid = -1;
	private static int strHrMid;
	private static int strMinMid;
	
	private static String regionFinal;				//string to hold value set by region, which will be added to .ics file
	private static int recurCount = -1;				//variable to hold count
	private static int recurInterval = -1;			//variable to hold interval
	private static boolean needUntil = false;		//boolean used to tell whether an end date was set (for recurrence)
	private static boolean needInterval = false;    
	private static boolean needFreq = false;
	private static boolean needCount = false;
	private static boolean isRegionSet = false;		//checks whether the region has been set
	private static boolean needLocation = false; 
	private static boolean needComment = false;
	private static boolean needResources = false;
	
	private static int untilYrFinal = -1;			//int to hold year/month/day of until date (recurrence)
	private static int untilMtFinal = -1;
	private static int untilDyFinal = -1;
	
		
	//runs gui method
	public static void main(String[] args){
		createAndShowGUI();
		
						
			
	}

	
	private static void createAndShowGUI() {
	
		JFrame frame = new JFrame("Calender Event");
		//frame.setSize(00,400);
		frame.setLayout(new FlowLayout());
		Point pt = new Point(300,10);
		
		String[] classes = {"Private", "Public", "Confidential"};
		//creating options for years
		//enter the amount of years you want your calendar to have options for
		String[] years = {"2019", "2018", "2017", "2016", "2015", "2014", "2013"};
							 
		String[] timeZones =  { "Etc/GMT+12",
								"Pacific/Samoa, US/Samoa",
								"US/Hawaii",
								"US/Alaska",
								"America/Los_Angeles",
								"America/Denver",
								"US/Central",
								"US/Eastern",
								"America/Virgin",
								"Brazil/East",
								"Etc/GMT+2",
								"Etc/GMT+1",
								"UCT",
								"Europe/Berlin",
								"Europe/Athens",
								"Europe/Moscow",
								"Asia/Dubai",
								"Indian/Maldives",
								"Asia/Thimbu",
								"Asia/Saigon",
								"Asia/Hong_Kong",
								"Asia/Tokyo",
								"Australia/Sydney",
								"Etc/GMT-11",
								"Pacific/Fiji",
								"Pacific/Tongatapu",
								"Etc/GMT-14"								
							  };
				
		//string array to hold all months
		String[] months = {"12 Dec","11 Nov","10 Oct","09 Sep","08 Aug","07 Jul","06 Jun",
			"05 May","04 Apr","03 Mar","02 Feb","01 Jan"};    
		
		
		//string array to hold all possible choices of a day
		daysLong = new String[31];
		for(int r = 1; r < 32; r++){
			daysLong[r-1] = r + "";
		}
		//string array to hold all possilbe choices of hours				
		String[] hours = new String[25];
			for(int n = 0; n < 25; n++){
				hours[n] = n + "";
			}
			hours[24] = "0";
			//string array to hold all possilbe choices of hours		
		String[] minutes = new String[61];
		for(int q = 0; q < 60; q++){
			minutes[q] = q + "";
		}
			minutes[60] = "0";	
	//creates the combobox with a string array as a parameter	
	drpYears = new DropDownMenu(years);
	drpMonths = new DropDownMenu(months);
	drpDayLong = new DropDownMenu(daysLong);
	drpTimeHr = new DropDownMenu(hours);
	drpTimeMin = new DropDownMenu(minutes);
	
	drpYearsMid = new DropDownMenu(years);
	drpMonthsMid = new DropDownMenu(months);
	drpDayLongMid = new DropDownMenu(daysLong);
	drpTimeHrMid = new DropDownMenu(hours);
	drpTimeMinMid = new DropDownMenu(minutes);
	
	drpYrUntil = new DropDownMenu(years);
	drpMthUntil = new DropDownMenu(months);
	drpDayUntil = new DropDownMenu(daysLong);
	
	drpRegion = new DropDownMenu(timeZones);
	
	drpClazz = new DropDownMenu(classes);
	
	//creates seperate combobox variable;
	comboYears = drpYears.getCBox();
	comboMonths = drpMonths.getCBox();
	comboDaysLong = drpDayLong.getCBox();
	comboHours = drpTimeHr.getCBox();
	comboMinutes = drpTimeMin.getCBox();
	
	comboYearsMid = drpYearsMid.getCBox();
	comboMonthsMid = drpMonthsMid.getCBox();
	comboDaysLongMid = drpDayLongMid.getCBox();
	comboHoursMid = drpTimeHrMid.getCBox();
	comboMinutesMid = drpTimeMinMid.getCBox();
	
	untilYr = drpYrUntil.getCBox();
	untilMth = drpMthUntil.getCBox();
	untilDay = drpDayUntil.getCBox();
	
	region = drpRegion.getCBox();
	clazzes = drpClazz.getCBox();
	
	//sets the scrollbar length
	comboYears.setMaximumRowCount(comboYears.getModel().getSize());
	comboMonths.setMaximumRowCount(comboMonths.getModel().getSize());
	comboDaysLong.setMaximumRowCount(comboDaysLong.getModel().getSize()-10);
	comboHours.setMaximumRowCount(comboHours.getModel().getSize()-10);
		
	comboYearsMid.setMaximumRowCount(comboYearsMid.getModel().getSize());
	comboMonthsMid.setMaximumRowCount(comboMonthsMid.getModel().getSize());
	comboDaysLongMid.setMaximumRowCount(comboDaysLongMid.getModel().getSize());
	comboHoursMid.setMaximumRowCount(comboHoursMid.getModel().getSize()-10);
		
	untilYr.setMaximumRowCount(untilYr.getModel().getSize());
	untilMth.setMaximumRowCount(untilMth.getModel().getSize());
	untilDay.setMaximumRowCount(untilDay.getModel().getSize());
	region.setMaximumRowCount(untilDay.getModel().getSize()-10);
	
	//enabled and disabled components for start up appearance
	//creating initial program look
	disabled(comboYearsMid);
	disabled(comboMonthsMid);
	disabled(comboDaysLongMid);
	disabled(comboMinutesMid);
	disabled(comboHoursMid);
	
	isAllDay = new JCheckBox("Is All Day Event");
	rule = new JCheckBox("Create Rule");
	changeYr = new JCheckBox("Change Year, Month and Day");
	regionCheck = new JCheckBox("Change TimeZone:");
	addResources = new JCheckBox("Add Resources");
	addComment = new JCheckBox("Add Comment");
	addLocation = new JCheckBox("Add Location");
	
	changeYr.setEnabled(false);
	
	create = new JButton("Create Calendar Event!");
	reset = new JButton("Reset");
	createRule = new JButton("Set Rule");
	ruleReset = new JButton("Reset Rule");
		
	daily = new JRadioButton("Daily");
	weekly = new JRadioButton("Weekly");
	monthly = new JRadioButton("Monthly");
	yearly = new JRadioButton("Yearly");
	
	noEndDate = new JRadioButton("No end date:");
	endAfter = new JRadioButton("End after:");
	endBy = new JRadioButton("End by:");
		
	//setting the default values all of the components should have
	//when the applications starts up
	
	daily.setEnabled(false);
	weekly.setEnabled(false);
	monthly.setEnabled(false);
	yearly.setEnabled(false);
	
	createRule.setEnabled(false);
	ruleReset.setEnabled(false);
	noEndDate.setEnabled(false);
	endAfter.setEnabled(false);
	endBy.setEnabled(false);
	regionCheck.setEnabled(false);
	
	text = new JTextField("type event here...         ");
	count = new JTextField("       ");
	endAfterText = new JTextField("       ");
	location = new JTextField("type location here...         ");
	comment = new JTextField("type comment here...           ");
	resources = new JTextField("type resources here...       ");
	
	calEvent = new JLabel("Enter Calendar Event:");
	recurEvery = new JLabel("                 Recur every");
	recurEvery.setEnabled(false);
	count.setEnabled(false);
	
	occur = new JLabel("occurence(s)");
	
	count.setEnabled(false);
	endAfterText.setEnabled(false);
	occur.setEnabled(false);
	location.setEnabled(false);
	comment.setEnabled(false);
	resources.setEnabled(false);
	//recurAfter = new JLabel(freq);
	//fffg
	
	calendarEvent.add(calEvent);
	calendarEvent.add(text);
	
	//adds mouse listener that clears the text when it is selected
	text.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e){
            text.setText("");
        }
    });
	
	location.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e){
            location.setText("");
        }
    });
	
	comment.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e){
            comment.setText("");
        }
    });
	
	resources.addMouseListener(new MouseAdapter(){
        @Override
        public void mouseClicked(MouseEvent e){
            resources.setText("");
        }
    });
	//action listener that saves event summary when entered by user
	text.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			JTextField txt = (JTextField) event.getSource();
			strTxt = (String)txt.getText();
			//array.add(strTxt);
			txt.setEnabled(false);
			
			
		}
	});
	//action listener that saves event location when entered by user
	location.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			JTextField loc = (JTextField) event.getSource();
			strLocation = (String)loc.getText();
			needLocation = true;
			//array.add(strTxt);
			location.setEnabled(false);
			
			
		}
	});
	//action listener that saves event comment when entered by user
	comment.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			JTextField com = (JTextField) event.getSource();
			strComment= (String)com.getText();
			needComment = true;
			//array.add(strTxt);
			comment.setEnabled(false);
			
			
		}
	});
	//action listener that saves event resources when entered by user
	resources.addActionListener(new ActionListener() {
		public void actionPerformed(ActionEvent event) {
			JTextField res = (JTextField) event.getSource();
			String resource = (String)res.getText();
			
			resourceList = new TextList(resource);
			needResources = true;
			//array.add(strTxt);
			resources.setEnabled(false);
			
			
		}
	});
	
	
	//action listeners for starting date
	comboYears.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
            // Get the source of the component, which is our combo
            JComboBox comboBox = (JComboBox) event.getSource();
            //saves the string selected by user as int
            String str = (String)comboBox.getSelectedItem();
            strYr = Integer.parseInt(str);
            
            comboYears.setEnabled(false);
            //checks to see if opposite 2 have been selected, if yes then checks date
         if(comboMonths.isEnabled() == false && comboDaysLong.isEnabled() == false){
            if(dateCheck(strYr, strMth, strDay) == false){
        		//System.out.println("date check false");
        		enabled(comboYears);
        		enabled(comboMonths);
        		enabled(comboDaysLong);
        	}else{
        		 comboYears.setEnabled(false);
        	}
         }    
            //checks to see if all values for start date have been selected
         	//if true enables ending date to be selected
            if(isTopGrey() == true){
            	//sets ending default yr/mth/day the same as starting date
            	comboYearsMid.setSelectedItem(comboYears.getSelectedItem());
            	comboMonthsMid.setSelectedItem(comboMonths.getSelectedItem());
            	comboDaysLongMid.setSelectedItem(comboDaysLong.getSelectedItem());
            	enableNeeded();
            	          	
            }
                       
        }
    });
	
	//month action listener
	comboMonths.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
            // Get the source of the component, which is our combobox.
            JComboBox comboBox = (JComboBox) event.getSource();
            
            //saves the string selected by user as int
            //takes the substring str because values are format "1 Jan"
            String str = (String)comboBox.getSelectedItem();
            String parseStr = str.substring(0,2);
            
            //saves to variable that will be used in calendar
            strMth = Integer.parseInt(parseStr);
            comboMonths.setEnabled(false);
        if(comboYears.isEnabled() == false && comboDaysLong.isEnabled() == false){
            if(dateCheck(strYr, strMth, strDay) == false){
        		System.out.println("date check false");
        		enabled(comboYears);
        		enabled(comboMonths);
        		enabled(comboDaysLong);
        	}else{
        		comboMonths.setEnabled(false);
        	}
        } 	
            
            
            //sets combobox to false to it cannot be changed
            //unless reset button is used
            
            
            if(isTopGrey() == true){
            	comboYearsMid.setSelectedItem(comboYears.getSelectedItem());
            	comboMonthsMid.setSelectedItem(comboMonths.getSelectedItem());
            	comboDaysLongMid.setSelectedItem(comboDaysLong.getSelectedItem());
            	enableNeeded();
            }
                                  
        }
    });
	
	comboDaysLong.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
            // Get the source of the component, which is our combo box.
            JComboBox comboBox = (JComboBox) event.getSource();

            String str = (String)comboBox.getSelectedItem();
            strDay = Integer.parseInt(str);
            comboDaysLong.setEnabled(false);
        if(comboMonths.isEnabled() == false && comboYears.isEnabled() == false){    
            if(dateCheck(strYr, strMth, strDay) == false){
        		System.out.println("date check false");
        		enabled(comboYears);
        		enabled(comboMonths);
        		enabled(comboDaysLong);
        	}else{
        		comboDaysLong.setEnabled(false);
        	}
        }               
            //sets combobox to false to it cannot be changed
            //unless reset button is used
            
            if(isTopGrey() == true){
            	comboYearsMid.setSelectedItem(comboYears.getSelectedItem());
            	comboMonthsMid.setSelectedItem(comboMonths.getSelectedItem());
            	comboDaysLongMid.setSelectedItem(comboDaysLong.getSelectedItem());
            	enableNeeded();
            }
                        
        }
    });
	
	comboHours.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo box.
            JComboBox comboBox = (JComboBox) event.getSource();
            //saves string
            String str = (String)comboBox.getSelectedItem();
            strHr = Integer.parseInt(str);
            
            //disables combobox
            comboHours.setEnabled(false);
            
            if(isTopGrey() == true){
            	comboYearsMid.setSelectedItem(comboYears.getSelectedItem());
            	comboMonthsMid.setSelectedItem(comboMonths.getSelectedItem());
            	comboDaysLongMid.setSelectedItem(comboDaysLong.getSelectedItem());
            	enableNeeded();
            }
                        
        }
    });
	
	comboMinutes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo box.
            JComboBox comboBox = (JComboBox) event.getSource();

            String str = (String)comboBox.getSelectedItem();
            strMin = Integer.parseInt(str);
            //sets false
            comboMinutes.setEnabled(false);
            
            if(isTopGrey() == true){
            	//System.out.println("inside isTopGrey()");
            	comboYearsMid.setSelectedItem(comboYears.getSelectedItem());
            	comboMonthsMid.setSelectedItem(comboMonths.getSelectedItem());
            	comboDaysLongMid.setSelectedItem(comboDaysLong.getSelectedItem());
            	enableNeeded();
            }            
            
        }
    }); //end action listener for top Level;
	
	
	//setting action listeners for midlevel
	comboYearsMid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo box.
            JComboBox comboBox = (JComboBox) event.getSource();

            // Print the selected items and the action command.
            String str = (String)comboBox.getSelectedItem();
            strYrMid = Integer.parseInt(str);
            
           
            //sets false
            comboYearsMid.setEnabled(false);
            
            if(strYrMid < strYr){
            	JOptionPane.showMessageDialog(null, "Opps, end year " + strYrMid + " cannot be before start year " + strYr);
            	comboYears.setEnabled(true);
            	comboYearsMid.setEnabled(true);
            }
            
            if(comboMonthsMid.isEnabled() == false && comboDaysLongMid.isEnabled() == false){
                if(dateCheck(strYrMid, strMthMid, strDayMid) == false){
            		//System.out.println("date check false");
            		enabled(comboYearsMid);
            		enabled(comboMonthsMid);
            		enabled(comboDaysLongMid);
            	}else{
            		 comboYearsMid.setEnabled(false);
            	}
             }
        }
    });
	
	comboMonthsMid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo box.
       
            JComboBox comboBox = (JComboBox) event.getSource();
            //saves string chose
            String str = (String)comboBox.getSelectedItem();
            String parseStr = str.substring(0,2);
            strMthMid = Integer.parseInt(parseStr);
            //sets combobox to false
            comboMonthsMid.setEnabled(false);
            
            if(strYr == strYrMid && strMth > strMthMid){
            	JOptionPane.showMessageDialog(null, "Opps, end month " + strMthMid + " cannot be before start month " + strMth);
            	comboMonths.setEnabled(true);
            	comboMonthsMid.setEnabled(true);
            }   
            
            if(comboYearsMid.isEnabled() == false && comboDaysLongMid.isEnabled() == false){
                if(dateCheck(strYrMid, strMthMid, strDayMid) == false){
                	enabled(comboYearsMid);
            		enabled(comboMonthsMid);
            		enabled(comboDaysLongMid);
            	}else{
            		 comboMonthsMid.setEnabled(false);
            	}
             }
            
        }
    });
	
	comboDaysLongMid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo box.
 
            JComboBox comboBox = (JComboBox) event.getSource();
            //saves string
            String str = (String)comboBox.getSelectedItem();
            strDayMid = Integer.parseInt(str);
            
            comboDaysLongMid.setEnabled(false);
            
            if(strYr == strYrMid && strMth == strMthMid && strDay > strDay){
            	JOptionPane.showMessageDialog(null, "Opps, end day " + strDayMid + " cannot be before start day " + strDay);
            	comboDaysLong.setEnabled(true);
            	comboDaysLongMid.setEnabled(true);
            }
            
            if(comboMonthsMid.isEnabled() == false && comboYearsMid.isEnabled() == false){
                if(dateCheck(strYrMid, strMthMid, strDayMid) == false){
            		//System.out.println("date check false");
            		enabled(comboYearsMid);
            		enabled(comboMonthsMid);
            		enabled(comboDaysLongMid);
            	}else{
            		 comboDaysLongMid.setEnabled(false);
            	}
             }
                        
        }
    });
	
	comboHoursMid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo
            // box.
            //
            JComboBox comboBox = (JComboBox) event.getSource();

            String str = (String)comboBox.getSelectedItem();
            strHrMid = Integer.parseInt(str);
            
            comboHoursMid.setEnabled(false);
            
            if(strYr == strYrMid && strMth == strMthMid && strDay == strDayMid && strHr > strHrMid){
            	JOptionPane.showMessageDialog(null, "Opps, end hour " + strHrMid + " cannot be before start hour " + strHr);
            	comboHours.setEnabled(true);
            	comboHoursMid.setEnabled(true);
            }
                        
        }
    });
	
	comboMinutesMid.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our combo
            // box.
            //
            JComboBox comboBox = (JComboBox) event.getSource();

            String str = (String)comboBox.getSelectedItem();
            strMinMid = Integer.parseInt(str);
            
            comboMinutesMid.setEnabled(false);
              
            if(strYr == strYrMid && strMth == strMthMid && strDay == strDayMid && strHr == strHrMid && strMin > strMinMid){
            	JOptionPane.showMessageDialog(null, "Opps, end hour " + strMinMid + " cannot be before start hour " + strMin);
            	comboMinutes.setEnabled(true);
            	comboMinutesMid.setEnabled(true);
            }
        }
    });
	
	//action listener that calls method to create calendar
	create.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            //
            // Get the source of the component, which is our JButton
            JButton but = (JButton) event.getSource();
            
            if(region.isEnabled() == false){
            	isRegionSet = false;
            }
            	//validates the date and makes sure that all settings that are
            	//supposed to be set are set, if not shows dialog
            	if(allGrey() == true){
            	boolean date = isDateValid(strYr,strMth,strDay,strHr,strMin, strYrMid, strMthMid, strDayMid, strHrMid, strMinMid);
            		if(date == true){
            			//if(region.isEnabled() == false){
            			createCalendar();
            			JOptionPane.showMessageDialog(null, "Calendar Created!");
            			resetBoard();
            		            		
            		}
            		
            	}else{
            		JOptionPane.showMessageDialog(null, "All Options Have Not Been Selected.\nMake sure to press <ENTER> after typing event text)");
            	
            		 }

                        
        }
    });
	//enabled options to set a recurrence rule only if start date is completed
	rule.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	if(isTopGrey() == false){
        		JOptionPane.showMessageDialog(null, "Complete start date first.");
        		rule.setSelected(false);
        		
    		}else{
            
            JCheckBox box = (JCheckBox) event.getSource();
            
            boolean bol = box.isSelected();
            //recurrence settings that are enabled
            if(bol == true){
            	daily.setEnabled(true);
            	weekly.setEnabled(true);
            	monthly.setEnabled(true);
            	yearly.setEnabled(true);
            	//count.setEnabled(true);
            	//recurEvery.setEnabled(true);
            	ruleReset.setEnabled(true);
            	create.setEnabled(false);
            	isSet.setText("[NOT SET]");
            	 	
            }else{
            	//recurrence settings disabled
            	daily.setEnabled(false);
            	weekly.setEnabled(false);
            	monthly.setEnabled(false);
            	yearly.setEnabled(false);
            	count.setEnabled(false);
            	
            	daily.setSelected(false);
            	weekly.setSelected(false);
            	monthly.setSelected(false);
            	yearly.setSelected(false);
            	endAfter.setSelected(false);
            	endBy.setSelected(false);
            	noEndDate.setSelected(false);
            	ruleReset.setEnabled(false);
                       
            	recurAfter.setText("");
            	count.setText("      ");
            	endAfterText.setText("      ");
            	isSet.setText("");
            	
            	recurEvery.setEnabled(false);
            	create.setEnabled(true);
            }
            
        }
        }
    });
	//sets the ending hr to 23 and ending minute to 59, resets if unchecked
	isAllDay.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
        if(isTopGrey() == false){
        	JOptionPane.showMessageDialog(null, "Please finsih start date.");
        	isAllDay.setSelected(false);
        }
        	int yrTemp  =  strYrMid;
        	int mthTemp =  strMthMid;
        	int dayTemp =  strDayMid;
        	int hrTemp  =  strHrMid;
        	int minTemp =  strMinMid;
            //
            // Get the source of the component, which is our combo
            // box.
            //
            JCheckBox box = (JCheckBox) event.getSource();
            
            boolean bol = box.isSelected();
            
            if(bol == true){
            	disabled(comboHoursMid);
            	comboHoursMid.setSelectedItem("23");
            	disabled(comboMinutesMid);
            	comboMinutesMid.setSelectedItem("59");
            		
            	strYrMid = strYr; 
            	strMthMid = strMth;
            	strDayMid = strDay;
            	strHrMid = 23;
            	strMinMid = 59;
            }
            
            if (bol == false){
            	enabled(comboHoursMid);
            	enabled(comboMinutesMid);
            	 
            	strYrMid  = yrTemp;
            	strMthMid = mthTemp;
            	strDayMid = dayTemp;
            	strHrMid  = hrTemp;
            	strMinMid = minTemp;
            }

                        
        }
    });
	//ending date year month and day set by default, check this to change them
	changeYr.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
            JCheckBox box = (JCheckBox) event.getSource();
            
            boolean bol = box.isSelected();
                //enables ending year month and day                   
            	if(bol == true){
            		enabled(comboDaysLongMid);
            		enabled(comboYearsMid);
            		enabled(comboMonthsMid);
            	
            	}
            	//disables ending year month and day
            	if(bol == false){
            		disabled(comboDaysLongMid);
            		disabled(comboYearsMid);
            		disabled(comboMonthsMid);
            	}
            
        } 
        
    });
	//calls resetboard() which resets the board back to default settings
	reset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
           
            JButton but = (JButton) event.getSource();
            
            if(but.isEnabled() == true){
            	resetBoard();
            }
                        
        }
    });
	//recurrence option for the frequency, enables further recurrence options once selected
	daily.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
           JRadioButton but = (JRadioButton) event.getSource();
           isRadioOff();
            //boolean b = 
            if(but.isEnabled() == true){
            	freqReset();
            	recurAfter.setText("day(s) - press enter after value");
            	
            	needFreq = true;
            	recur.setFrequency("DAILY");
            	monthly.setSelected(false);
            	weekly.setSelected(false);
            	yearly.setSelected(false);
            	
            	count.setEnabled(true);
            	recurEvery.setEnabled(true);
            	
            	daily.setEnabled(false);
            }
                        
        }
    });
	
	//recurrence option for the frequency, enables further recurrence options once selected
	weekly.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	isRadioOff();
        	freqReset();
            JRadioButton but = (JRadioButton) event.getSource();
            
            if(but.isEnabled() == true){
            	recurAfter.setText("week(s) - press enter after value");
            	recur.setFrequency("WEEKLY");
            	needFreq = true;
            	monthly.setSelected(false);
            	daily.setSelected(false);
            	yearly.setSelected(false);
            	count.setEnabled(true);
            	recurEvery.setEnabled(true);
            	
            	weekly.setEnabled(false);
            }
                        
        }
    });
	//recurrence option for the frequency, enables further recurrence options once selected
	monthly.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	isRadioOff();        
        	freqReset();
            JRadioButton but = (JRadioButton) event.getSource();
            if(but.isEnabled() == true){
            	recurAfter.setText("month(s) - press enter after value");
            	recur.setFrequency("MONTHLY");
            	needFreq = true;
            	weekly.setSelected(false);
            	daily.setSelected(false);
            	yearly.setSelected(false);
            	count.setEnabled(true);
            	recurEvery.setEnabled(true);
            	
            	monthly.setEnabled(false);
            }
                        
        }
    });
	//recurrence option for the frequency, enables further recurrence options once selected
	yearly.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	isRadioOff();
        	freqReset();
            JRadioButton but = (JRadioButton) event.getSource();
            
            if(but.isEnabled() == true){
            	recurAfter.setText("year(s) - press enter after value");
            	recur.setFrequency("YEARLY");
            	needFreq = true;
            	weekly.setSelected(false);
            	daily.setSelected(false);
            	monthly.setSelected(false);
            	count.setEnabled(true);
            	recurEvery.setEnabled(true);
            	
            	yearly.setEnabled(false);
            }
                        
        }
    });
	//lets user input interval value; ie recur every ? days/weeks/months/years
	count.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
           
            JTextField but = (JTextField) event.getSource();
            
            String str = (String)count.getText(); 		//gets string input by user
            String str2 = str.replaceAll(" ",""); 		//replaces all empty spaces
            
            try { 
               recurInterval = Integer.parseInt(str2); 
               //enables further recurrence options - when will the event end
                if(recurInterval > 0){
                	recur.setInterval(recurInterval);
                	noEndDate.setEnabled(true);
                	endAfter.setEnabled(true);
                	//endAfterText.setEnabled(false);
                	//occur.setEnabled(false);
                	endBy.setEnabled(true);
                	needInterval = true;
                	count.setEnabled(false);
                	recurEvery.setEnabled(false);
                	recurAfter.setEnabled(false);
                }
                else{
                	JOptionPane.showMessageDialog(null, "Please only enter integers greater than 0");
                	count.setText("      ");
                }
            } catch(NumberFormatException e) { 
            	JOptionPane.showMessageDialog(null, "Please only enter integers");
            	count.setText("      ");
            	freqReset();
            }
                        	
            }
                        
       });
	//sets recurrence property Count - end after ? occurences
	endAfterText.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
           
            JTextField but = (JTextField) event.getSource();
            
            String str = (String)endAfterText.getText();
            String str2 = str.replaceAll(" ","");
            
            try { 
               int counter = Integer.parseInt(str2); 
               //recur.setCount(afterText);
                if (counter > 0){
                	recurCount = counter;
                	createRule.setEnabled(true);
                	needCount = true;
                }else{
                	JOptionPane.showMessageDialog(null, "Please enter integers greater than 0");
                	endAfterText.setText("      ");
                }
            } catch(NumberFormatException e) { 
            	JOptionPane.showMessageDialog(null, "Please only enter integers");
            	endAfterText.setText("      ");
            	
            } 
            	
            }
                        
       });
	//no end date means the event continues forever
	noEndDate.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	isRadioRecurOff();
        	createRule.setEnabled(false);
        	createRule.setEnabled(true);
        	untilDate(false);
        	needUntil = false;
        	needCount = false;
            JRadioButton but = (JRadioButton) event.getSource();
            
            if(but.isEnabled() == true){
            	endAfterText.setText("      ");
            	endAfterText.setEnabled(false);
            	occur.setEnabled(false);
            	
            	endAfter.setSelected(false);
            	endBy.setSelected(false);          	
            	noEndDate.setEnabled(false);
            	
            	
            }
                        
        }
    });
	//
	endAfter.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	isRadioRecurOff();
        	createRule.setEnabled(false);
        	untilDate(false);
        	needCount = true;
        	needUntil = false;
            JRadioButton but = (JRadioButton) event.getSource();
            
            if(but.isEnabled() == true){
            	occur.setEnabled(true);
            	endAfterText.setEnabled(true);
            	noEndDate.setSelected(false);
            	endBy.setSelected(false);
            	
            	           	
            	endAfter.setEnabled(false);
            }
                        
        }
    });
	//sets until date - event will continue until yyyy/dd/mm
	endBy.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	isRadioRecurOff();
        	createRule.setEnabled(false);
        	untilYr.setEnabled(true);
        	needUntil = true;
        	needCount = false;
            JRadioButton but = (JRadioButton) event.getSource();
            
            if(but.isEnabled() == true){
            	endAfterText.setText("      ");
            	endAfterText.setEnabled(false);
            	occur.setEnabled(false);
            	
            	
            	noEndDate.setSelected(false);
            	endAfter.setSelected(false);
            	         	
            	endBy.setEnabled(false);
            }
                        
        }
    });
	
	//enables and disables region based on checkbox
	regionCheck.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	regionFinal = "";
        	isRegionSet = false;
            JCheckBox but = (JCheckBox) event.getSource();
            
            boolean bol = but.isSelected();
            if(bol = true){
            	region.setEnabled(true);
            	regionCheck.setSelected(false);
            	regionCheck.setEnabled(false);
            }else{
            	region.setEnabled(false);
            }
        }
    });
	//
	untilYr.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JComboBox but = (JComboBox) event.getSource();
        	String str = (String)but.getSelectedItem();
        	untilYrFinal = Integer.parseInt(str);
        	//checks if ending year is greater then until year for logical errors
        	if(strYrMid > untilYrFinal){
        		JOptionPane.showMessageDialog(null,"Opps, ending year " + strYrMid + " cannot be greater than end-by year " + untilYrFinal);
        		untilYr.setEnabled(true);
        	}else{
        		untilYr.setEnabled(false);
        		untilMth.setEnabled(true);
        	}
        	//enables button to set rule
        	if(untilMth.isEnabled() == false && untilYr.isEnabled() == false && untilDay.isEnabled() == false){
        		createRule.setEnabled(true);
        	}
        	
        }
    });
	
	untilMth.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JComboBox but = (JComboBox) event.getSource();
        	String str = (String)but.getSelectedItem();
        	String substr = str.substring(0,2);
        	untilMtFinal = Integer.parseInt(substr);
        	//checks for logical error when inputting until date
        	if(strYrMid == untilYrFinal && strMthMid > untilMtFinal){
        		JOptionPane.showMessageDialog(null,"Opps, ending month " + strMthMid + " cannot be greater than end-by month " + untilMtFinal);
        		untilMth.setEnabled(true);
        	}else{
        		untilMth.setEnabled(false);
        		untilDay.setEnabled(true);
        	}
        	if(untilMth.isEnabled() == false && untilYr.isEnabled() == false && untilDay.isEnabled() == false){
        		createRule.setEnabled(true);
        	}
        }
    });
	
	untilDay.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JComboBox but = (JComboBox) event.getSource();
        	String str = (String)but.getSelectedItem();
        	untilDyFinal = Integer.parseInt(str);
        	if(strYrMid == untilYrFinal && strMthMid == untilMtFinal && strDayMid > untilDyFinal){
        		JOptionPane.showMessageDialog(null,"Opps, ending day " + strMthMid + " cannot be greater than end-by day " + untilMtFinal);
        		untilDay.setEnabled(true);
        	}else{
        		untilDay.setEnabled(false);
        		needUntil = true;
        	}
        	if(untilMth.isEnabled() == false && untilYr.isEnabled() == false && untilDay.isEnabled() == false){
        		createRule.setEnabled(true);
        	}
        	
        }
    });
	
	region.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JComboBox but = (JComboBox) event.getSource();
        	regionFinal = (String)but.getSelectedItem();
        	region.setEnabled(false);
        	regionCheck.setSelected(false);
        	regionCheck.setEnabled(true);
        	
        	isRegionSet = true;
        }
    });
	//sets the class to either private/public/confidential
	clazzes.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JComboBox but = (JComboBox) event.getSource();
        	String temp = (String)but.getSelectedItem();
        	
        	if(but.getSelectedIndex() == 0){
        		
        		finalClass = "PRIVATE";
        	}
        	
        	if(but.getSelectedIndex() == 1){
        		
        		finalClass = "PUBLIC";
        	}
        	
        	if(but.getSelectedIndex() == 2){
        		
        		finalClass = "CONFIDENTIAL";
        	}
        	
        	clazzes.setEnabled(false);
        }
    });
	//enables resources to be added
	addResources.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
        	JCheckBox but = (JCheckBox) event.getSource();
            resources.setEnabled(true);
            needResources = true;
            
            if(addResources.isSelected() == true){
            	resources.setEnabled(true);
            }else{
            	resources.setEnabled(false);
            	resources.setText("type resources here...       ");
            	needResources = false;
            }
        }
    });
	//enables comments to be enabled
	addComment.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
            JCheckBox but = (JCheckBox) event.getSource();
            
            needComment = true;
            
            if(addComment.isSelected() == true){
            	comment.setEnabled(true);
            }else{
            	comment.setEnabled(false);
            	comment.setText("type comment here...           ");
            	needComment = false;
            }
        }
    });
	//enables location to be added
	addLocation.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	
            JCheckBox but = (JCheckBox) event.getSource();
            
            needLocation = true;
            
            if(addLocation.isSelected() == true){
            	location.setEnabled(true);
            }else{
            	location.setEnabled(false);
            	location.setText("type location here...         ");
            	needLocation = false;
            }
        }
    });
	
	
	//validates the days chosen 
	createRule.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JButton but = (JButton) event.getSource();
        	//first successful case which needs an until date
        	if(needUntil == true){
        		if(inArray(untilYrFinal, untilMtFinal, untilDyFinal) == true){
        			JOptionPane.showMessageDialog(null,"Rule Set!");
        			isSet.setText("[RULE SET]");
        			afterRule();
        			create.setEnabled(true);
        		}
        		else{
        		JOptionPane.showMessageDialog(null, "Date appears to be invalid");
        		untilDate(true);
        		}
        	//second successful case with no until date
        	}else{
        		JOptionPane.showMessageDialog(null,"Rule Set!");
        		isSet.setText("RULE SET");
        		afterRule();
        		create.setEnabled(true);
        	}
        		
        	
        }
    });
	//resets only the recurrence rule options
	ruleReset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
        	JButton but = (JButton) event.getSource();
        	resetRule();
        	daily.setEnabled(true);
    		weekly.setEnabled(true);
    		monthly.setEnabled(true);
    		yearly.setEnabled(true);
    		count.setEnabled(false);
    		recurEvery.setEnabled(false);
    		
    		daily.setSelected(false);
    		weekly.setSelected(false);
    		monthly.setSelected(false);
    		yearly.setSelected(false);
    		needInterval = false;
        	needCount = false;
        	needFreq = false;
        	needUntil = false;
        }
    });
	
	//creates instance variables of Layout Mangers
	FlowLayout flow = new FlowLayout(FlowLayout.LEFT, 5, 10);
	GridLayout grid = new GridLayout(0,1);
			
	JLabel startDate = new JLabel("Choose Starting Time:");
	JLabel endDate = new JLabel("Choose Ending Time:  ");
	JLabel regSelect = new JLabel("Select TimeZone");
	JLabel clazzSelect = new JLabel("Select Class");
	
	//method in DropDownMenu class that creates a JPanel with a string and JComboBox
	//as parameters
	JPanel theYears = drpYears.getPanel("Year:", comboYears);
	JPanel theMonths = drpMonths.getPanel("Month:", comboMonths);
	JPanel theDayLong = drpDayLong.getPanel("Day:", comboDaysLong);
	JPanel theHours = drpTimeHr.getPanel("Hour:", comboHours);
	JPanel theMinutes = drpTimeMin.getPanel("Minute:", comboMinutes);
	JPanel theYearsMid = drpYears.getPanel("Year:", comboYearsMid);
	JPanel theMonthsMid = drpMonths.getPanel("Month:", comboMonthsMid);
	JPanel theDayLongMid = drpDayLong.getPanel("Day:", comboDaysLongMid);
	JPanel theHoursMid = drpTimeHr.getPanel("Hour:", comboHoursMid);
	JPanel theMinutesMid = drpTimeMin.getPanel("Minute:", comboMinutesMid);
	JPanel theYearsUntil = drpYears.getPanel(yr, untilYr);
	JPanel theMonthsUntil = drpYears.getPanel(mt, untilMth);
	JPanel theDaysUntil = drpYears.getPanel(dy, untilDay);
	JPanel theRegionPanel = drpRegion.getPanel(regSelect, region);
	JPanel theClazzPanel = drpClazz.getPanel(clazzSelect, clazzes);
	
	
	resourcesPanel = new JPanel(grid);
	commentPanel = new JPanel(grid);
	locationPanel = new JPanel(grid);
	
	resourcesPanel.add(resources);
	resourcesPanel.add(addResources);
	
	commentPanel.add(comment);
	commentPanel.add(addComment);
	
	locationPanel.add(location);
	locationPanel.add(addLocation);
	
	//sets default status of until comboboxes
	untilYr.setEnabled(false);
	untilMth.setEnabled(false);
	untilDay.setEnabled(false);
	
	yr.setEnabled(false);
	mt.setEnabled(false);
	dy.setEnabled(false);
	
	theMonthsUntil.setEnabled(false);
	theDaysUntil.setEnabled(false);
	
	//constructs each panel row by row, adding panels onto the right via flowlayout
	
	regionPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,20,10));
	regionPanel.add(theRegionPanel);
	regionPanel.add(regionCheck);
	regionPanel.add(theClazzPanel);
	
	recurPanel.add(recurEvery);
	recurPanel.add(count);
	recurPanel.add(recurAfter);
	
	endAfterPan = new JPanel(new FlowLayout());
	endAfterPan.add(endAfter);
	endAfterPan.add(endAfterText);
	endAfterPan.add(occur);
	
	
	
	
	topLevel.setLayout(new FlowLayout(FlowLayout.LEFT,20,10));
	topLevel.add(startDate);
	topLevel.add(theYears);
	topLevel.add(theMonths);
	topLevel.add(theDayLong);
	
	topLevel.add(theHours);
	topLevel.add(theMinutes);
	topLevel.add(isAllDay);
		
	midLevel.setLayout(new FlowLayout(FlowLayout.LEFT,20,10));
	midLevel.add(endDate);
	midLevel.add(theYearsMid);
	midLevel.add(theMonthsMid);
	midLevel.add(theDayLongMid);
	midLevel.add(theHoursMid);
	midLevel.add(theMinutesMid);
	midLevel.add(changeYr);
	
	botLevel.setLayout(new FlowLayout(FlowLayout.LEFT, 20, 10));
	botLevel.add(rule);
	//botLevel.add(calendarEvent);
	botLevel.add(text);
	botLevel.add(locationPanel);
	botLevel.add(commentPanel);
	botLevel.add(resourcesPanel);
	botLevel.add(create);
	botLevel.add(reset);
	
	thirdLevel.setLayout(flow);
	thirdLevel.add(new JLabel("Recurrence Pattern and Range: "));
	thirdLevel.add(isSet);
		
	fourthLevel.setLayout(flow);
	fourthLevel.add(daily);
	fourthLevel.add(recurPanel);
	
	fifthLevel.setLayout(flow);
	fifthLevel.add(weekly);
	fifthLevel.add(new JLabel("          "));
	fifthLevel.add(noEndDate);
	
	sixthLevel.setLayout(flow);
	sixthLevel.add(monthly);
	sixthLevel.add(new JLabel("        "));
	sixthLevel.add(endAfterPan);
	
	seventhLevel.setLayout(flow);
	seventhLevel.add(yearly);
	seventhLevel.add(new JLabel("             "));
	seventhLevel.add(endBy);
	seventhLevel.add(theYearsUntil);
	seventhLevel.add(theMonthsUntil);
	seventhLevel.add(theDaysUntil);
	
	eighthLevel.setLayout(flow);
	eighthLevel.add(createRule);
	eighthLevel.add(ruleReset);
	
	theGrid.setVgap(15);
	theGrid.setHgap(10);
	boxLay.setLayout(theGrid);
	
	//adding all flowlayout managers to gridlayout manager (nested layouts)
	boxLay.add(regionPanel);
	boxLay.add(topLevel);
	boxLay.add(midLevel);
	boxLay.add(botLevel);
	boxLay.add(thirdLevel);
	//boxLay.add(jPanDailyFull);
	
	
	boxLay.add(fourthLevel);
	//boxLay.add(recurPanel1);
	boxLay.add(fifthLevel);
	boxLay.add(sixthLevel);
	boxLay.add(seventhLevel);
	boxLay.add(eighthLevel);
	
		//finally adds nested layouts to frame
		frame.add(boxLay);		  
		frame.setLocation(pt);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			//sets default status
			comboMonths.setEnabled(true);
			comboDaysLong.setEnabled(true);
			comboHours.setEnabled(true);
			comboMinutes.setEnabled(true);
		
		
		frame.pack();
		frame.setVisible(true);
	
}

	public void actionPerformed(ActionEvent e) {
			//tracker++;
			//// TODO Auto-generated method stub
			
	                  		
		}
	//helper methods
	public static void enabled(JComponent boxEn){
		boxEn.setEnabled(true);
	}
	
	public static void disabled(JComponent boxDis){
		boxDis.setEnabled(false);
	}
	public static void deSeelct(JRadioButton comp){
		comp.setSelected(false);
	}
	
	public static void setBottom(boolean bol){
		comboYearsMid.setEnabled(bol);
		comboMonthsMid.setEnabled(bol);
		comboDaysLongMid.setEnabled(bol);
		comboMinutesMid.setEnabled(bol);
		comboHoursMid.setEnabled(bol);
		changeYr.setEnabled(bol);
		
		
	}
	//checks date using inArray() method
	public static boolean dateCheck(int year, int month, int day){
		if(year != -1 && month != -1 && day != -1){
			if(inArray(year,month,day) == false){
				String str = ("Date: " +  (month) + "/" + (day) + "/" + year + " is not valid.");
				JOptionPane.showMessageDialog(null, str );
				return false;
			}else{
				return true;
			}
		}
		return false;
	}
	//sets after rule status
	public static void afterRule(){
		daily.setEnabled(false);
		weekly.setEnabled(false);
		monthly.setEnabled(false);
		yearly.setEnabled(false);
		recurEvery.setEnabled(false);
		count.setEnabled(false);
		recurAfter.setEnabled(false);
		endAfter.setEnabled(false);
		noEndDate.setEnabled(false);
		endBy.setEnabled(false);
		count.setEnabled(false);
		endAfterText.setEnabled(false);
		createRule.setEnabled(false);
		occur.setEnabled(false);
		
	}
	public static void isRadioOff(){
		if(daily.isEnabled() == false){
			daily.setEnabled(true);
		}
		if(weekly.isEnabled() == false){
			weekly.setEnabled(true);
		}
		if(monthly.isEnabled() == false){
			monthly.setEnabled(true);
		}
		if(yearly.isEnabled() == false){
			yearly.setEnabled(true);
		}
	}
	//resets the recurrence rule section
	public static void resetRule(){
		freqReset();
		isSet.setText("[NOT SET]");
		createRule.setEnabled(false);
		recurEvery.setEnabled(true);
		count.setEnabled(true);
		recurAfter.setEnabled(true);
		recurAfter.setText("");
	}
	public static void isRadioRecurOff(){
		if(noEndDate.isEnabled() == false){
			noEndDate.setEnabled(true);
		}
		if(endBy.isEnabled() == false){
			endBy.setEnabled(true);
		}
		if(endAfter.isEnabled() == false){
			endAfter.setEnabled(true);
			endAfterText.setEnabled(true);
			occur.setEnabled(true);
		}
		if(yearly.isEnabled() == false){
			yearly.setEnabled(true);
		}
	}
	//sets until date comboboxes set enabled to value bol
	public static void untilDate(boolean bol){
		untilYr.setEnabled(bol);
		untilMth.setEnabled(bol);
		untilDay.setEnabled(bol);
		yr.setEnabled(bol);
		mt.setEnabled(bol);
		dy.setEnabled(bol);
	}
	public static boolean isTopDisabled(){
		
		boolean yr = comboYears.isEnabled();
		boolean mth = comboMonths.isEnabled();
		boolean dy = comboDaysLong.isEnabled();
		boolean min = comboMinutes.isEnabled();
		boolean hr = comboHours.isEnabled();
		//changeYr.isEnabled();
		
		if(yr == false && mth == false && dy == false && min == false && hr == false){
			return true;
		}
		
		return false;
		
	}
	
	public static void enableNeeded(){
		comboMinutesMid.setEnabled(true);
		comboHoursMid.setEnabled(true);
		changeYr.setEnabled(true);
		comboYearsMid.setEnabled(false);
	}
	
	public static boolean isTopGrey(){
		
		boolean yr = comboYears.isEnabled();
		boolean mth = comboMonths.isEnabled();
		boolean day = comboDaysLong.isEnabled();
		boolean hr = comboHours.isEnabled();
		boolean min = comboMinutes.isEnabled();
		//boolean txt = text.isEnabled();
		
		if(yr == false && mth == false && day == false && hr == false && min == false){
			return true;
		}
		
		
		return false;
		
	}
	
	
	
	public static boolean allGrey(){
		location.setEnabled(false);
		comment.setEnabled(false);
		resources.setEnabled(false);
		
		boolean yr = comboYears.isEnabled();
		boolean mth = comboMonths.isEnabled();
		boolean day = comboDaysLong.isEnabled();
		boolean hr = comboHours.isEnabled();
		boolean min = comboMinutes.isEnabled();
		boolean txtBol = text.isEnabled();
		
		boolean yrMid = comboYearsMid.isEnabled();
		boolean mthMid = comboMonthsMid.isEnabled();
		boolean dayMid = comboDaysLongMid.isEnabled();
		boolean hrMid = comboHoursMid.isEnabled();
		boolean minMid = comboMinutesMid.isEnabled();
		boolean reg = region.isEnabled();
		boolean clazz = clazzes.isEnabled();
		
		if(yr == false && mth == false && day == false && hr == false && min == false && 
				txtBol == false && yrMid == false && mthMid == false && dayMid == false && 
				hrMid == false && minMid == false && reg == false && clazz == false){
				return true;
		}
		return false;
	}
	
	
	public static boolean isDateValid(int stYear, int stMonth, int stDay, int stHr, int stMin,
								      int edYear, int edMonth, int edDay, int edHr, int edMin){
		
		String value = "";
		//sets years to 0-6 to match indexes of combobox years
		int stYearTemp = 0;
		
		if(stYear == 2014){
			stYearTemp = 1;
		}
		if(stYear == 2015){
			stYearTemp = 2;
		}
		if(stYear == 2016){
			stYearTemp = 3;
		}
		if(stYear == 2017){
			stYearTemp = 4;
		}
		if(stYear == 2018){
			stYearTemp = 5;
		}
		if(stYear == 2019){
			stYearTemp = 6;
		}
		
		
	
		
		if(inArray(stYearTemp, stMonth, stDay) == false){
			resetBoard();
			error = "Date appears to be invalid";
				return false;
		}
		//logic to make sure dates dont start after they end or end before they begin
		if(stYear > edYear){
			
			error = "Start year " + stYear + " is after end year " + edYear;
			comboYears.setEnabled(true);
			comboYearsMid.setEnabled(true);
			return false;
		}
		if(stYear == edYear && stMonth > edMonth){
			error = "Start month " + stMonth + " is after end month " + edMonth;
			comboMonths.setEnabled(true);
			comboMonthsMid.setEnabled(true);
			return false;
		}
		if(stYear == edYear && stMonth == edMonth && stDay > edDay){
			error = "Start day " + stDay + "is after end day " + edDay;
			comboDaysLong.setEnabled(true);
			comboDaysLongMid.setEnabled(true);
			return false;
		}
		if(stYear == edYear && stMonth == edMonth && stDay == edDay && stHr == edHr && stMin > edMin){
			error = "Start minute " + stMin + " is after end minute " + edMin;
			comboMinutesMid.setEnabled(true);
			comboMinutes.setEnabled(true);
			return false;
		}
		
		if(stYear == edYear && stMonth == edMonth && stDay == edDay && stHr > edHr){
			error = "Start hour " + stHr+ " is after end hour " + edHr;
			comboHoursMid.setEnabled(true);
			comboHours.setEnabled(true);
			return false;
		}
		//else if(stMonth )
		
		
		return true;
	}
	
	public static String dateToString(){
		String str = "yr = " + strYr + " month = " + strMth + " day = " + strDay + " hour = " + strHr + " min = " + strMin + "";
				
				return str;
	}
	public static boolean inArray(int stYear, int month, int day){

		String value = "";
		
		int stYearTemp = 0;
		
		if(stYear == 2014){
			stYearTemp = 1;
		}
		if(stYear == 2015){
			stYearTemp = 2;
		}
		if(stYear == 2016){
			stYearTemp = 3;
		}
		if(stYear == 2017){
			stYearTemp = 4;
		}
		if(stYear == 2018){
			stYearTemp = 5;
		}
		if(stYear == 2019){
			stYearTemp = 6;
		}
		dayTracker track = new dayTracker();
		//see dayTracker class
		isDay = track.createNYears();
		//System.out.println("inArray Method - stYearTemp = " + stYearTemp 
			//	+ " month = " + month + " day = " + day);
		//returns a -1 if the date does not exist
		if(isDay.get(stYearTemp).get(month-1)[day-1] == -1){
			return false;
		}
		
		return true;
	}

	//helper methods
	public static boolean isFreqRadioReset(){
		if(daily.isSelected() == false && weekly.isSelected() == false && monthly.isSelected() == false && yearly.isSelected() == false){
			return true;
		}
	
		
		return false;
	}
	//helper methods
	public static void freqReset(){
		count.setText("      ");
		noEndDate.setEnabled(false);
		endAfter.setEnabled(false);
		endBy.setEnabled(false);
		endAfterText.setText("      ");
		endAfterText.setEnabled(false);
		occur.setEnabled(false);
		untilYr.setEnabled(false);
		untilMth.setEnabled(false);
		untilDay.setEnabled(false);
		yr.setEnabled(false);
		mt.setEnabled(false);
		dy.setEnabled(false);
		
		endAfter.setSelected(false);
		endBy.setSelected(false);
		noEndDate.setSelected(false);
		
		
		
		
	}
	//resets board to default values
	public static void resetBoard(){
		
		enabled(comboYears);
		enabled(comboMonths);
		enabled(comboDaysLong);
		enabled(comboHours);
		enabled(comboMinutes);
		enabled(region);
		enabled(clazzes);
		
		disabled(comboYearsMid);
		disabled(comboMonthsMid);
		disabled(comboDaysLongMid);
		disabled(comboHoursMid);
		disabled(comboMinutesMid);
		
		
		regionCheck.setEnabled(false);
		createRule.setEnabled(false);
				
		isAllDay.setSelected(false);
		rule.setSelected(false);
		text.setEnabled(true);
		text.setText("type event here...         ");
		location.setEnabled(true);
		location.setText("type location here...         ");
		comment.setEnabled(true);
		comment.setText("type comment here...           ");
		resources.setEnabled(true);
		resources.setText("type resources here...       ");
		daily.setEnabled(false);
		weekly.setEnabled(false);
		monthly.setEnabled(false);
		yearly.setEnabled(false);
		count.setEnabled(false);
		
		daily.setSelected(false);
    	weekly.setSelected(false);
    	monthly.setSelected(false);
    	yearly.setSelected(false);
    	endAfter.setSelected(false);
    	noEndDate.setSelected(false);
    	endBy.setSelected(false);
    	addLocation.setSelected(false);
    	addComment.setSelected(false);
    	addResources.setSelected(false);
    	
    	recurEvery.setEnabled(false);
    	noEndDate.setEnabled(false);
    	endAfter.setEnabled(false);
    	endAfterText.setEnabled(false);
    	occur.setEnabled(false);
    	endBy.setEnabled(false);
    	untilYr.setEnabled(false);            	
    	untilMth.setEnabled(false);
    	untilDay.setEnabled(false);
    	yr.setEnabled(false);
    	mt.setEnabled(false);
    	dy.setEnabled(false);
    	changeYr.setEnabled(false);
    	changeYr.setSelected(false);
    	
    	endAfterText.setText("      ");
    	recurAfter.setText("");
    	ruleReset.setEnabled(false);
    	needInterval = false;
    	needCount = false;
    	needFreq = false;
    	needUntil = false;
    	needLocation = false;
    	
    	location.setEnabled(false);
    	comment.setEnabled(false);
    	resources.setEnabled(false);
    	
	}
	
	//method that actually creates the .ics file	
	public static void createCalendar(){
		//creating new calendar
				net.fortuna.ical4j.model.Calendar calendar = new net.fortuna.ical4j.model.Calendar();
				
				calendar.getProperties().add(Version.VERSION_2_0);
				calendar.getProperties().add(new ProdId("-//Robert Patch//iCal4j 2.0//EN"));
				calendar.getProperties().add(CalScale.GREGORIAN);
										
				//setting time zone
				TimeZone tz = TimeZone.getTimeZone(regionFinal);
				Calendar startCal = Calendar.getInstance(tz);
				startCal.set(strYr, strMth-1, strDay, strHr, strMin, 00);
				
				//setting end date
				Calendar endCal = Calendar.getInstance(tz);
				endCal.set(strYrMid, strMthMid-1, strDayMid, strHrMid, strMinMid, 00);
				
				//creating a new calendar for a recurrence until date
				Calendar untilCal = Calendar.getInstance(tz);
				
				//setting with values received from GUI
				untilCal.set(untilYrFinal, untilMtFinal-1, untilDyFinal);
				
				//creating event using VEvent
				DateTime start = new DateTime(startCal.getTime());
				DateTime end = new DateTime(endCal.getTime());
				DateTime until = new DateTime(untilCal.getTime());
				
				//checks if daily, monthly, weeky, and yearly are all disabled
				//if they are then none of them were ever selected, therefore no frequency
				if(isFreqRadioReset() == false){
					recur.setCount(recurCount);
					rrule = new RRule(recur);
				}
				
				
				if(needUntil == true){
					recur.setUntil(until);
				}
				//creating VEvent that will hold ical properties				
				VEvent event1 = new VEvent(start, end, strTxt);
				
				//only adds a frequency if one was selected
				if(isFreqRadioReset() == false){
					System.out.println("inside if state");
					event1.getProperties().add(rrule);
				}
				//adds location only if one was entered
				if(addLocation.isSelected() == true){
					//Location loc = new Location();
					event1.getProperties().add(new Location(strLocation));
				}
				//adds comment only if one was eneted
				if(addComment.isSelected() == true){
					event1.getProperties().add(new Comment(strComment));
				}
				//adds resources only if entered
				if(addResources.isSelected() == true){
					event1.getProperties().add(new Resources(resourceList));
				}
				//creates class with finalClass parameter
				Clazz clazz = new Clazz(finalClass);
					
				//adds clazz property to VEvent
				event1.getProperties().add(clazz);
				//event1.getProperties().add(version);
				//			
				String filename = "palmCalendar.ics";  //output file name
			
				UidGenerator uidGenerator = null;
				try {
					uidGenerator = new UidGenerator("1");
				} catch (SocketException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} //required by specifications
				event1.getProperties().add(uidGenerator.generateUid()); //required by specifications
				    
				    
				//adding event component to calendar    
				calendar.getComponents().add(event1);
				
				//outputting file via FileOutPutStream
				FileOutputStream output = null;
				try {
					output = new FileOutputStream(filename);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				CalendarOutputter outputter = new CalendarOutputter();
				try {
					outputter.output(calendar, output);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ValidationException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				  
				//parsing file as filename variable string data
				FileInputStream filein = null;
				try {
					filein = new FileInputStream(filename);
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				CalendarBuilder builder = new CalendarBuilder();
				try {
					calendar = builder.build(filein);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (ParserException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	}
	

}
